package com.visikard.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.visikard.application.Constant;
import com.visikard.item.ItemRTUICoupon;
import com.visikard.ui.R;
import com.visikard.utility.BitmapUtils;
import com.visikard.utility.UILImageUtils;
import com.visikard.utility.Utils;

public class RTUICouponAdapter extends BaseAdapter {

	private List<ItemRTUICoupon> mListData;
	private Context mContext;

	public RTUICouponAdapter(Context context) {
		mContext = context;
		mListData = new ArrayList<ItemRTUICoupon>();
	}

	public RTUICouponAdapter(Context context, List<ItemRTUICoupon> listData) {
		mContext = context;
		mListData = listData;
		if (mListData == null) {
			mListData = new ArrayList<ItemRTUICoupon>();
		}
	}

	@Override
	public int getCount() {
		return mListData.size();
	}

	@Override
	public ItemRTUICoupon getItem(int position) {
		if (position >= 0 && position < mListData.size())
			return mListData.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			view = inflater.inflate(R.layout.rtui_item_coupon_view, parent, false);
			Utils.overrideFonts(view, Constant.FONT_GOTHAM_BOOK);
			Holder holder = new Holder();
			holder.imgCoupon = (ImageView) view.findViewById(R.id.rtui_img_coupon);
			holder.txtDesc = (TextView) view.findViewById(R.id.rtui_text_description_coupon);
			holder.txtStatus = (TextView) view.findViewById(R.id.rtui_text_active);
			Utils.overrideFonts(holder.txtStatus, Constant.FONT_GOTHAM_BOLD);
			view.setTag(holder);
		}

		Holder holder = (Holder) view.getTag();
		ItemRTUICoupon item = getItem(position);

		if (item != null) {
			UILImageUtils.loadImage(holder.imgCoupon, // image view
					item.getFilename(), // url
					1, // size of view
					BitmapUtils.ROUND_NONE, // round all
					0, // round size
					0, // shadow
					R.drawable.kard_shadow_default_horizontal, // shadow resource
					0, 0);

			holder.txtDesc.setText(item.getTitle());
			holder.txtStatus.setText(item.getStatus());
		}

		return view;
	}

	private class Holder {
		ImageView imgCoupon;
		TextView txtDesc, txtStatus;
	}

}
